/***************************************************
> Copyright (C) 2024 ==QWZL== All rights reserved.
> File Name: queue.c
> Author:nxq
> Mail:nxq949698473@163.com 
> Created Time: 2024年07月12日 星期五 16时19分27秒
***************************************************/

//实现一个队列，queue.c queue.h  先进先出
#include "queue.h"

//Info * Creatr()
//创建链表文件
struct queue *create_queue()
{
    struct queue* head = NULL;//头结点
    head = (struct queue*)malloc(sizeof(struct queue));//申请空间
    memset(head,0,sizeof(struct queue));
    return head;
};


//入队，尾插
void push(int data,struct queue *que)//struct queue *que头节点
{
    struct queue *node = NULL;
    struct queue *cur = que;

    while(cur->next != NULL)//找到链表尾部
    {
        cur = cur->next;
    }

    node = (struct queue*)malloc(sizeof(struct queue));
    memset(node,0,sizeof(struct queue));

    node->data = data;//新节点存储数据

    cur->next = node;
    node->next = NULL;

}

//获取队第一个节点点元素
int front(struct queue *que)
{
    struct queue* cur = que->next;
    int data;
    data = cur->data;
    return data;
}

//出队 删除队头节点 -- 头删
void pop(struct queue *que)
{
    struct queue *temp = que;
    temp = temp->next;
    que->next = temp->next;

    free(temp);
    temp = NULL;

}

//判断队列是否为空
int isempty(struct queue *que)
{
    struct queue *cur = que;
    if(cur->next == NULL)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

//释放
void queue_relsase(struct queue *que)
{
    struct queue* cur= que->next;
    struct queue* temp= NULL;
    while(cur != NULL)
    {
        temp = cur;
        free(temp);
        temp = NULL;
        cur = cur->next;
    }

}